﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Web.Model;
using Core.DataAccess.Model.Projects;
using Core.Framework.Model.Common;
using Core.Framework.Util;
using Core.IBusiness.IProjectModule;
using Microsoft.AspNetCore.Mvc;

namespace Core.Web.Controllers.Project
{
    /// <summary>
    /// 项目管理
    /// </summary>
    [Route(".v1/project/[controller]")]
    [ApiController]
    [ApiProjectMemberAuthorize]
    public class AppController : BaseApiController
    {
        public AppController(IProject iProject) :
             base(iProject: iProject)
        {
        
        }
        

        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <param name="model">额外事件实体</param>
        /// <returns></returns>
        [HttpPost(".GetAppList")]
        public IResult GetAppList(AppListRequest model)
        {

            var result = this.iProject.GetProjectList(iProjectUserInfo.Id, model.search, model.pagination);

            return new ApiResult
            {
                code = result.IsFinished ? CodeResult.SUCCESS : CodeResult.DATA_NOT_FOUND,
                date = result.Date,
                info = result.Discription
            };
        }




        /// <summary>
        /// 添加项目
        /// </summary>
        /// <param name="model">项目实体</param>
        /// <returns></returns>
        [HttpPost]
        public IResult POST(ProjectList model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iProject.ProjectExec(
                        model, SqlExecType.insert));
                }, model.IsValid(IsValidEnum.reg));
        }



        /// <summary>
        /// 修改项目信息
        /// </summary>
        /// <param name="model">项目实体</param>
        /// <returns></returns>
        [HttpPut]
        public IResult Put(ProjectList model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iProject.ProjectExec(
                        model,
                        SqlExecType.update));
                }, model.IsValid(IsValidEnum.update));
        }


    }
}